#ifndef CPP_VIEWGROUP_H
#define CPP_VIEWGROUP_H

#include <widget/View.h>
#include <utils/Timer.h>
#include <vector>

class Context;
class KeyEvent;

//@brief 容器
//@author cvte
//@description 容器控件
class ViewGroup : public View {
   public:
    typedef std::vector<View*> ViewVector;
    friend class ActivityManager;
    ViewGroup();
    ViewGroup(Context& context);
    virtual ~ViewGroup();

    ViewGroup* getClassType();
    virtual bool containView(View* view);
    virtual void eraseView(View* view);

    void create(HWND parent);
    virtual void addView(View* view);
    void removeView(View* view);
    virtual View* findViewById(int id);
    void setVisibility(int visibility);
    //@method 设置识别物理按键长按的时间，默认3000ms，超时会回调onKeyLongPress
    void setKeyLongPressTimeMs(int timeMs);
    //@method 获取识别物理按键长按的时间
    int getKeyLongPressTimeMs();
    //@method void draw(Canvas& canvas)
    //＠description 将该控件绘制到指定画布上，默认使用该控件的坐标
    virtual void draw(Canvas& canvas);
    //@method void draw(Canvas& canvas, int x, int y);
    //＠description 将该控件绘制到指定画布上，并指定要绘制该控件的坐标
    virtual void draw(Canvas& canvas, int x, int y);
    //@method 获取控件集合
    ViewVector* getViews();
    //@method 删除所有控件
    void removeAllViews();
    //@method 设置控件是否在视频背景上
    void setOnVideoBackground(bool isOn);

   protected:
    ViewVector mViews;
    KeyEvent mLastKeyEvent;
    long mKeyLongPressTimerTaskId = -1;
    Timer mKeyLongPressTimer;
    int mKeyLongPressTimeMs = 0; //ViewGroup默认不支持长按
    void sendNotify(int notifyId, void* data = nullptr);
    void onNotify(int notifyId, void* data);
    void dispatchKeyEvent(KeyEvent& keyEvent);

   private:
    Context* mContext;
};

#endif /* CPP_VIEWGROUP_H */